package com.eonmind.vip.provider;


import cn.hutool.core.util.ObjectUtil;
import com.eonmind.common.contract.data.response.ResponseEntity;
import com.eonmind.common.contract.timer.Timer;
import com.eonmind.common.provider.entity.vip.PointsConsumption;
import com.eonmind.common.provider.entity.vip.UserWelfare;
import com.eonmind.vip.contract.api.VipToUserFeignService;
import com.eonmind.vip.mapper.PointsMapper;
import com.eonmind.vip.mapper.UserWelfareMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

@RestController
public class VipToUserServerProvider implements VipToUserFeignService {
    @Autowired
    private UserWelfareMapper userWelfareMapper;

    @Autowired
    private PointsMapper pointsMapper;


    @Override
    public ResponseEntity<Boolean> initUserWelfare(Long userId) {
        if (ObjectUtil.isEmpty(userId)) {
            return ResponseEntity.fail("参数出错");
        }
        UserWelfare.CachedFeatures cachedFeatures = new UserWelfare.CachedFeatures();
        cachedFeatures
                // 设置累计总积分
                .setAllCoins(10000)
                // 设置每日可获取的积分
                .setDailyCoins(0)
                // 设置当前可用积分
                .setTotalCoins(10000)
                // 设置累计使用积分
                .setUsedCoins(0)
                .setFeatures(new UserWelfare.CachedFeatures.Features().setChat(20).setVideo(5).setDrawing(5));
        UserWelfare userWelfare = new UserWelfare()
                .setUserId(userId)
                .setUpdateTime(Timer.currentTimestamp())
                .setDel(0)
                .setCreateTime(Timer.currentTimestamp())
                .setActiveSubscriptionIds(new ArrayList<>())
                .setSubscriptionHistoryIds(new ArrayList<>())
                .setCachedFeatures(cachedFeatures);
        userWelfareMapper.save(userWelfare);

        PointsConsumption pointsConsumption1 = new PointsConsumption().setConsumption(+10000)
                .setCategory("获取")
                .setUserID(userId)
                .setBalance(10000)
                .setType(4)
                .setCreateTime(Timer.currentTimestamp())
                .setDescription("新人福利"+10000+"积分")
                .setUpdateTime(Timer.currentTimestamp());
        pointsMapper.save(pointsConsumption1);

        return ResponseEntity.success(true);
    }
}
